package NotifyTest;

public class ChiHuo extends Thread {
    private BaoZi bz;//1.创建包子变量

    public ChiHuo(BaoZi bz) {
        this.bz = bz;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (bz) {
                if (bz.flag == false) {

                    try {
                        bz.wait();//等待生产
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println("吃货正在吃:"+ bz.pi + bz.xian +"的包子");
                bz.flag = false;
                bz.notify();//唤醒包子铺线程，生产包
                System.out.println("吃货已经把:"+bz.pi + bz.xian +"包子吃完了，包子铺开始生成包子");
            }
        }
    }
}